﻿/*************************************************************************
 * Created by OhZee Creative, LLC
 * 2013
 * This code is licensed under Microsoft Public License (Ms-PL)
 * http://opensource.org/licenses/ms-pl
 * http://ozframework.codeplex.com/
 *************************************************************************/

namespace OhZeeCreative.Windows8.Converters
{
	using System;
	using Windows.UI.Xaml;
	using Windows.UI.Xaml.Data;
	using Windows.UI.Xaml.Media;

    public sealed class DependencyObjectToVisualAncestorConverter : IValueConverter
	{
		public int Levels { get; set; }

		public object Convert(object value, Type targetType, object parameter, string language)
		{
			DependencyObject dob = value as DependencyObject;
			
			for (int i = 0; i < Levels && dob != null; i++)
			{
				dob = VisualTreeHelper.GetParent(dob);
			}

			return dob;
		}

		public object ConvertBack(object value, Type targetType, object parameter, string language)
		{
			throw new NotImplementedException();
		}
	}
}
